Skip to main content
Version: 1.x.x

Global Defaults


Use global defaults for command

To significantly limit the setup of our application, we can add global configs. To get the greatest flexibility in the context of the created configurations in larger and more complex applications, they are added through callbacks based on command data. Thanks to this, we can, for example, make one default configuration for requests using the get method and another for the others.

It is worth remembering that global configurations are overwritten by command settings, so the options that we set will be applied only to commands that do not have them specified in their options.


Example

export const builder = new Builder({ url }).setCommandConfig((commandOptions) => {
if (commandOptions.method === "GET") {
return {
deduplicate: true,
cacheTime: 20000,
retry: 3,
};
}

return {
deduplicate: false,
cache: false,
retry: 0,
};
});